package com.luck.easyfoodbatch.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.luck.easyfoodbatch.R;
import com.luck.easyfoodbatch.entity.Share;
import com.luck.easyfoodbatch.util.Tools;

import java.util.ArrayList;
import java.util.List;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.adapter
 * email：893855882@qq.com
 * data：16/9/2
 */
public class ShareAdapter extends BaseAdapter {
    private List<Share> list = new ArrayList<>();
    private Context mContext;
    private LayoutInflater from;

    public ShareAdapter(Context mContext) {
        super();
        this.mContext = mContext;
        from = LayoutInflater.from(mContext);
        Share share;
        for (int i = 0; i < 3; i++) {
            share = new Share();
            switch (i) {
                case 0:
                    share.setName("Q Q");
                    share.setShareResId(R.mipmap.ssdk_oks_classic_qq);
                    break;
                case 1:
                    share.setName("微 信");
                    share.setShareResId(R.mipmap.ssdk_oks_classic_wechat);
                    break;
                case 2:
                    share.setName("朋友圈");
                    share.setShareResId(R.mipmap.ssdk_oks_classic_wechatmoments);
                    break;
            }
            list.add(share);
        }
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder;
        if (view == null) {
            holder = new Holder();
            view = from.inflate(R.layout.share_item, null);
            holder.sdk_oks_name = (TextView) view.findViewById(R.id.sdk_oks_name);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        Share share = list.get(i);
        holder.sdk_oks_name.setText(share.getName());
        Tools.modifyTextViewDrawable(mContext, holder.sdk_oks_name, share.getShareResId(), 1);
        return view;
    }

    class Holder {
        TextView sdk_oks_name;
    }
}
